import random

def generate_matchsticks(num, total_length=None):
    if total_length is not None:
        # 构造能构成正方形的情况（总和能被4整除）
        side = total_length // 4
        result = []
        for _ in range(4):
            current = [random.randint(1, side) for _ in range(num // 4)]
            current[-1] = side - sum(current[:-1])
            result.extend(current)
        random.shuffle(result)
        return result
    else:
        # 构造无法构成正方形的情况
        return [random.randint(1, 20) for _ in range(num)]

if __name__ == "__main__":
    print(generate_matchsticks(12, 60))  # Example: 构成正方形
    print(generate_matchsticks(10))      # Example: 可能无法构成正方形
